package com.kun.config;

import lombok.extern.slf4j.Slf4j;
import org.csource.common.MyException;
import org.csource.fastdfs.ClientGlobal;
import org.csource.fastdfs.StorageClient1;
import org.csource.fastdfs.TrackerClient;
import org.csource.fastdfs.TrackerServer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

@Slf4j
@Configuration
public class FastDfsConfig {

    @Bean
    public StorageClient1 fastDFSClient() {
        try {
            // 加载配置文件
            ClientGlobal.initByProperties("fastdfs-client.properties");
            // 创建 tracker 客户端
            TrackerClient trackerClient = new TrackerClient();
            TrackerServer trackerServer = trackerClient.getTrackerServer();
            // 定义 storage 客户端
            return new StorageClient1(trackerServer, null);
        } catch (IOException | MyException e) {
            log.error("fastdfs初始化失败：{}", e.getMessage());
            return null;
        }
    }

}
